/*
    10. Write a program in C to find maximum occurring character in a string. 

    Test Data :
    Input the string : Welcome to w3resource.com.

    Expected Output :

    The Highest frequency of character 'e' 
    appears number of times : 4 
*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

char* getstr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p = ch;
        p++;
    }
    *p = '\0';
    return str;
}

void countHighFreChar(char *str)
{
    char ch[26];
    int i, index, max = 0;
    memset(ch, 0, 26);
    while(*str != '\0'){
        if(isalpha(*str))
            ch[*str - 'a']++;
        str++;
    }
    for(i = 0; i < 26; i++){
        if(ch[i] > max){
            max = ch[i];
            index = i;
        }            
    }
    printf("The Highest frequency of character '%c'\n", 'a' + index);
    printf("appears number of times : %d\n", max);
}

int main(void)
{
    char *str = malloc(1024);
    printf("Input the string : ");
    getstr(str);
    countHighFreChar(str);
    return 0;
}